/**
 * Created by shenguolin on 2023/8/22 9:26
 * lowcode-front
 * Description:
 */
import store from '@/store'

const mixin = {
  data() {
    return {
      search: {
        projectId: ''
      }
    }
  },
  computed: {
    changeHeaderProject() {
      return store.state.settings.changeHeaderProject
    }
  },
  watch: {
    changeHeaderProject: {
      immediate: false,
      handler: function(val) {
        if (!this.$headerSearch) {
          return
        }
        if (val != '') {
          //如果选择的不是 所有项目
          let key = 'projectId'
          let key2 = 'sectionId'
          this.$set(this.search, key, val)
          this.$set(this.search, key2, '')
          if(!!this.sectionTree&&!!this.projectTree){
            this.projectTree.forEach((item) => {
              if (item.id === this.search.projectId) {
                this.sectionTree = item.children
                if(this.title == '勘察施工图成果'||this.publicSearchType == '标段默认选中'||this.title == '合同清单'){
                  this.$set(this.search, key2, this.sectionTree[0].id)
                }
              }
            })
          }
          if(this.title == '标准化管理'||this.title == '品质工程'){
            this.$set(this, 'projectId', val)
            this.changeProject()
          }
          if(this.title == '准入厂家名单台账'||this.title == '隐患库'){
            // this.$set(this, 'projectId', val)
            this.getLeftTreeNew()
          }
          if(this.title == '合同台账'||this.title == '合同支付台账'){
            this.$set(this.search, 'projectId', val)
            this.getCompanyIdBypryojectId()
            return
          }
        if(this.title == '合同清单'){
          this.seledSection(this.search.sectionId)
        }else if(this.title == '勘察施工图成果'||this.title == '统计报表') {
            this.getLeftTrees()
          }else {
            this.getList(true)
          }
        } else {
          //不限项目
          let key = 'projectId'
          let key2 = 'sectionId'
          if(this.title == '合同台账'||this.title == '合同支付台账'){
            this.getCompanyIdBypryojectId()
            return
          }
          if(this.title == '勘察施工图成果'||this.title == '统计报表'||this.title == '合同清单'){
            this.$set(this.search, key, this.projectTree[0].id)
            if(!!this.sectionTree&&!!this.projectTree){
              this.projectTree.forEach((item) => {
                if (item.id === this.search.projectId) {
                  this.sectionTree = item.children
                  if(this.title == '勘察施工图成果'||this.title == '统计报表'||this.title == '合同清单'){
                    this.$set(this.search, key2, this.sectionTree[0].id)
                  }
                }
              })
              if(this.title == '勘察施工图成果'||this.title == '统计报表'){
                this.getLeftTrees()
              }
              if(this.title == '合同清单'){
                this.seledSection(this.search.sectionId)
              }
            }
          }else {
            let arr = ['攻坚作战图','计量期设置','材料调差报表册']
            if(arr.includes(this.title)){
              //该数组里面的title  需要默认选中第一个项目
              if(this.projectTree.length>0){
                this.$set(this.search, key, this.projectTree[0].id)
              }
            }else{
              this.$set(this.search, key, val)
            }
             if(this.publicSearchType == '标段默认选中'){
               if(!!this.sectionTree&&!!this.projectTree){
                 this.projectTree.forEach((item) => {
                   if (item.id === this.search.projectId) {
                     this.sectionTree = item.children
                     this.$set(this.search, key2, this.sectionTree[0].id)
                   }
                 })
               }
             }else {
               this.$set(this.search, key2, '')
               if(!!this.sectionTree){
                 this.sectionTree = []
               }
             }
            this.getList(true)
          }
          if(this.title == '标准化管理'||this.title == '品质工程'){
            this.getProjectSectionInfoTree()
          }
         
        }

      }
    }
  },
  methods: {}
}
export default mixin
